from typing import List



class Solution:
    def searchRange(self, nums: List[int], target: int) -> List[int]:
        leftBoundaryIndex = self.binarySearchWithBoundary(nums, target, True)
        rightBoundaryIndex = self.binarySearchWithBoundary(nums, target, False)
        if leftBoundaryIndex > rightBoundaryIndex or leftBoundaryIndex < 0 or rightBoundaryIndex == len(nums):
            return [-1, -1]
        else:
            return [leftBoundaryIndex, rightBoundaryIndex]

    def binarySearchWithBoundary(self, nums: List[int], target: int, isLeftBoundary: bool) -> int:
        left, right = 0, len(nums) - 1
        ans = -1
        while left <= right:
            mid = left + ((right - left) >> 1)
            if isLeftBoundary:
                if nums[mid] >= target:
                    ans = mid
                    right = mid - 1
                else:
                    left = mid + 1
            else:
                if nums[mid] <= target:
                    ans = mid
                    left = mid + 1
                else:
                    right = mid - 1
        return ans